{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://raw.githubusercontent.com/BobXWu/TopMost/master/data/Amazon_Review.zip\n",
      "Using downloaded and verified file: ./datasets/Amazon_Review.zip\n"
     ]
    }
   ],
   "source": [
    "import topmost\n",
    "from topmost import download_dataset\n",
    "\n",
    "device = \"cuda\" # or \"cpu\"\n",
    "dataset_dir = \"./datasets/Amazon_Review\"\n",
    "download_dataset('Amazon_Review', cache_path='./datasets')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://raw.githubusercontent.com/BobXWu/TopMost/master/data/dict.zip\n",
      "Using downloaded and verified file: ./datasets/dict.zip\n"
     ]
    }
   ],
   "source": [
    "dict_dir = './datasets/dict'\n",
    "download_dataset('dict', cache_path='./datasets')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# load a preprocessed dataset\n",
    "dataset = topmost.CrosslingualDataset(dataset_dir, lang1='en', lang2='cn', dict_path=f'{dict_dir}/ch_en_dict.dat', device=device, batch_size=128)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  1%|          | 5/500 [00:17<28:13,  3.42s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 005 loss: 6.729 loss_TAMI: 2.135\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  2%|▏         | 10/500 [00:34<27:38,  3.39s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 010 loss: 6.556 loss_TAMI: 2.129\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  3%|▎         | 15/500 [00:51<27:20,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 015 loss: 6.493 loss_TAMI: 2.128\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  4%|▍         | 20/500 [01:07<27:02,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 020 loss: 6.466 loss_TAMI: 2.127\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  5%|▌         | 25/500 [01:24<26:45,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 025 loss: 6.455 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  6%|▌         | 30/500 [01:41<26:28,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 030 loss: 6.441 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  7%|▋         | 35/500 [01:58<26:11,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 035 loss: 6.432 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  8%|▊         | 40/500 [02:15<25:54,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 040 loss: 6.422 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  9%|▉         | 45/500 [02:32<25:38,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 045 loss: 6.416 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 10%|█         | 50/500 [02:49<25:22,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 050 loss: 6.406 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 11%|█         | 55/500 [03:05<25:04,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 055 loss: 6.401 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 12%|█▏        | 60/500 [03:22<24:47,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 060 loss: 6.399 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 13%|█▎        | 65/500 [03:39<24:30,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 065 loss: 6.389 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 14%|█▍        | 70/500 [03:56<24:13,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 070 loss: 6.385 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 15%|█▌        | 75/500 [04:13<23:56,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 075 loss: 6.381 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 16%|█▌        | 80/500 [04:30<23:39,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 080 loss: 6.380 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 17%|█▋        | 85/500 [04:47<23:23,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 085 loss: 6.369 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 18%|█▊        | 90/500 [05:04<23:06,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 090 loss: 6.372 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 19%|█▉        | 95/500 [05:20<22:49,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 095 loss: 6.369 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 20%|██        | 100/500 [05:37<22:32,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 100 loss: 6.364 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 21%|██        | 105/500 [05:54<22:15,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 105 loss: 6.366 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 22%|██▏       | 110/500 [06:11<21:58,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 110 loss: 6.361 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 23%|██▎       | 115/500 [06:28<21:41,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 115 loss: 6.358 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 24%|██▍       | 120/500 [06:45<21:24,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 120 loss: 6.354 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 25%|██▌       | 125/500 [07:02<21:07,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 125 loss: 6.352 loss_TAMI: 2.126\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 26%|██▌       | 130/500 [07:18<20:50,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 130 loss: 6.337 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 27%|██▋       | 135/500 [07:35<20:33,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 135 loss: 6.336 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 28%|██▊       | 140/500 [07:52<20:17,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 140 loss: 6.336 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 29%|██▉       | 145/500 [08:09<19:59,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 145 loss: 6.337 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 30%|███       | 150/500 [08:26<19:43,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 150 loss: 6.334 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 31%|███       | 155/500 [08:43<19:26,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 155 loss: 6.334 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 32%|███▏      | 160/500 [09:00<19:09,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 160 loss: 6.334 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 33%|███▎      | 165/500 [09:16<18:52,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 165 loss: 6.332 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 34%|███▍      | 170/500 [09:33<18:35,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 170 loss: 6.331 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 35%|███▌      | 175/500 [09:50<18:18,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 175 loss: 6.331 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 36%|███▌      | 180/500 [10:07<18:03,  3.39s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 180 loss: 6.333 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 37%|███▋      | 185/500 [10:24<17:45,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 185 loss: 6.332 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 38%|███▊      | 190/500 [10:41<17:28,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 190 loss: 6.326 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 39%|███▉      | 195/500 [10:58<17:10,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 195 loss: 6.326 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 40%|████      | 200/500 [11:15<16:54,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 200 loss: 6.327 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 41%|████      | 205/500 [11:31<16:37,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 205 loss: 6.326 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 42%|████▏     | 210/500 [11:48<16:20,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 210 loss: 6.325 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 43%|████▎     | 215/500 [12:05<16:03,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 215 loss: 6.329 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 44%|████▍     | 220/500 [12:22<15:46,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 220 loss: 6.324 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 45%|████▌     | 225/500 [12:39<15:29,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 225 loss: 6.325 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 46%|████▌     | 230/500 [12:56<15:12,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 230 loss: 6.328 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 47%|████▋     | 235/500 [13:13<14:56,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 235 loss: 6.324 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 48%|████▊     | 240/500 [13:30<14:39,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 240 loss: 6.325 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 49%|████▉     | 245/500 [13:46<14:22,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 245 loss: 6.323 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 50%|█████     | 250/500 [14:03<14:05,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 250 loss: 6.324 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 51%|█████     | 255/500 [14:20<13:48,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 255 loss: 6.318 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 52%|█████▏    | 260/500 [14:37<13:31,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 260 loss: 6.313 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 53%|█████▎    | 265/500 [14:54<13:14,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 265 loss: 6.315 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 54%|█████▍    | 270/500 [15:11<12:57,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 270 loss: 6.317 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 55%|█████▌    | 275/500 [15:28<12:40,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 275 loss: 6.314 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 56%|█████▌    | 280/500 [15:44<12:23,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 280 loss: 6.314 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 57%|█████▋    | 285/500 [16:01<12:06,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 285 loss: 6.315 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 58%|█████▊    | 290/500 [16:18<11:50,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 290 loss: 6.319 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 59%|█████▉    | 295/500 [16:35<11:33,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 295 loss: 6.318 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 60%|██████    | 300/500 [16:52<11:16,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 300 loss: 6.310 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 61%|██████    | 305/500 [17:09<10:59,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 305 loss: 6.311 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 62%|██████▏   | 310/500 [17:26<10:42,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 310 loss: 6.318 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 63%|██████▎   | 315/500 [17:43<10:25,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 315 loss: 6.314 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 64%|██████▍   | 320/500 [17:59<10:08,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 320 loss: 6.316 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 65%|██████▌   | 325/500 [18:16<09:51,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 325 loss: 6.312 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 66%|██████▌   | 330/500 [18:33<09:34,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 330 loss: 6.310 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 67%|██████▋   | 335/500 [18:50<09:18,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 335 loss: 6.312 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 68%|██████▊   | 340/500 [19:07<09:01,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 340 loss: 6.314 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 69%|██████▉   | 345/500 [19:24<08:44,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 345 loss: 6.315 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 70%|███████   | 350/500 [19:41<08:28,  3.39s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 350 loss: 6.316 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 71%|███████   | 355/500 [19:58<08:10,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 355 loss: 6.313 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 72%|███████▏  | 360/500 [20:14<07:53,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 360 loss: 6.313 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 73%|███████▎  | 365/500 [20:31<07:36,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 365 loss: 6.313 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 74%|███████▍  | 370/500 [20:48<07:19,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 370 loss: 6.312 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 75%|███████▌  | 375/500 [21:05<07:02,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 375 loss: 6.312 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 76%|███████▌  | 380/500 [21:22<06:45,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 380 loss: 6.310 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 77%|███████▋  | 385/500 [21:39<06:28,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 385 loss: 6.308 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 78%|███████▊  | 390/500 [21:56<06:11,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 390 loss: 6.307 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 79%|███████▉  | 395/500 [22:12<05:55,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 395 loss: 6.307 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 80%|████████  | 400/500 [22:29<05:38,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 400 loss: 6.309 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 81%|████████  | 405/500 [22:46<05:21,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 405 loss: 6.309 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 82%|████████▏ | 410/500 [23:03<05:04,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 410 loss: 6.309 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 83%|████████▎ | 415/500 [23:20<04:47,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 415 loss: 6.308 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 84%|████████▍ | 420/500 [23:37<04:30,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 420 loss: 6.306 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 85%|████████▌ | 425/500 [23:54<04:13,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 425 loss: 6.309 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 86%|████████▌ | 430/500 [24:11<03:56,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 430 loss: 6.306 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 87%|████████▋ | 435/500 [24:27<03:39,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 435 loss: 6.309 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 88%|████████▊ | 440/500 [24:44<03:22,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 440 loss: 6.311 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 89%|████████▉ | 445/500 [25:01<03:06,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 445 loss: 6.306 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 90%|█████████ | 450/500 [25:18<02:49,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 450 loss: 6.307 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 91%|█████████ | 455/500 [25:35<02:32,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 455 loss: 6.304 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 92%|█████████▏| 460/500 [25:52<02:15,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 460 loss: 6.309 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 93%|█████████▎| 465/500 [26:09<01:58,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 465 loss: 6.306 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 94%|█████████▍| 470/500 [26:25<01:41,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 470 loss: 6.308 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 95%|█████████▌| 475/500 [26:42<01:24,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 475 loss: 6.307 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 96%|█████████▌| 480/500 [26:59<01:07,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 480 loss: 6.305 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 97%|█████████▋| 485/500 [27:16<00:50,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 485 loss: 6.310 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 98%|█████████▊| 490/500 [27:33<00:33,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 490 loss: 6.305 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " 99%|█████████▉| 495/500 [27:50<00:16,  3.38s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 495 loss: 6.310 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 500/500 [28:07<00:00,  3.37s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 500 loss: 6.306 loss_TAMI: 2.125\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "# create a model\n",
    "model = topmost.InfoCTM(\n",
    "    trans_e2c=dataset.trans_matrix_en,\n",
    "    pretrain_word_embeddings_en=dataset.pretrained_WE_en,\n",
    "    pretrain_word_embeddings_cn=dataset.pretrained_WE_cn,\n",
    "    vocab_size_en=dataset.vocab_size_en,\n",
    "    vocab_size_cn=dataset.vocab_size_cn,\n",
    "    weight_MI=50\n",
    ")\n",
    "model = model.to(device)\n",
    "\n",
    "# create a trainer\n",
    "trainer = topmost.CrosslingualTrainer(model, dataset, lr_scheduler='StepLR', lr_step_size=125, epochs=500)\n",
    "# train the model\n",
    "top_words_en, top_words_cn, train_theta_en, train_theta_cn = trainer.train()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Topic 0: stress ink layout paper paperback print prints silver printer thick printing slight layer colors legal\n",
      "Topic 1: worn crew tire gun address cash trash staff complaint church boot door agent broke wrist\n",
      "Topic 2: sunday r press ship slow respond rest dan yesterday night morning afternoon re moon day\n",
      "Topic 3: adult baby parents children width dad parenting draw prefer mother plain house adults greek everyday\n",
      "Topic 4: yesterday afternoon blow files p cardboard file shock compact speed moment gift download load birthday\n",
      "Topic 5: knife knives shoe socks sharp comfortable round size dan pants blade cutting sells feet tax\n",
      "Topic 6: loves toy daughter son toys baby doll children grandson sister smile girl kids parents year\n",
      "Topic 7: potter season magic episodes seasons clever spare rob harry series final tip caught devil priced\n",
      "Topic 8: doctor household parent maintain health patient collar train child method dog control cure human ill\n",
      "Topic 9: matrix risk invest bank logic factor aid dough mold firm conflict freedom option beta goal\n",
      "Topic 10: river diet eat suffer foods restaurant eating destroy food meals protein cook soup worlds rice\n",
      "Topic 11: civil race nation biblical church religion belief courage christ christian gods christians western human saga\n",
      "Topic 12: camera lens nikon canon d zoom logic textbook field focus sport camcorder teach pictures interface\n",
      "Topic 13: yoga workout workouts sweat gym mile beginner pregnant sky sore instruction challenging hurt shaving comfort\n",
      "Topic 14: recipes tea travel india eat healthy map protein kitchen flavor foods tasty ice restaurant soup\n",
      "Topic 15: format bluray dvd global bend versions dollar version cheap vhs hit remastered complete blu bargain\n",
      "Topic 16: stores western station share west joy shop christmas brings spend bike bring models store accident\n",
      "Topic 17: sky silent tender neighborhood grace tension rhythm sun warm proud valley epic belong poetic pile\n",
      "Topic 18: concepts analysis examples practical concise staff introductory introduction overview guide advanced explaining information schools basic\n",
      "Topic 19: spiritual career path road bitter russell wisdom inspirational paris miserable task wealth practical dream leader\n",
      "Topic 20: characters ending character relationship plot male romance town storyline premise suspense mystery protagonist clever likable\n",
      "Topic 21: refund ordered amazon sent seller fake company item manufacturer shipped packaging received contacted arrived items\n",
      "Topic 22: game graphics gameplay games controls playstation ps xbox controller played mei chi fun playing team\n",
      "Topic 23: chapter reader replacement authors chapters pages readers informative bible reading books stories writing bucks information\n",
      "Topic 24: cross pin flip next finished passion finish reread books reading read ultra found wait rob\n",
      "Topic 25: trash editor publishers fabric joke steer rob grab bore moral attack mess edited poorly vietnam\n",
      "Topic 26: violin tie bulb performance tension daily brief tragic orchestra rhythm relief breath delightful recommended cast\n",
      "Topic 27: lid bottom wrench pot floor rubber screw holder water rack stove nylon tight seat jar\n",
      "Topic 28: foreign england american british south north revolution prose african america mr southern bank classic english\n",
      "Topic 29: referred refer build floor r stand desk window factual tag explained front push board building\n",
      "Topic 30: arrived limit fast satisfied pen ultra quickly condition thanks cash easy purchase birth delivery male\n",
      "Topic 31: coffee printer maker cartridges grinder grind ink prints filters beans moral printing element cup drip\n",
      "Topic 32: passion protagonist fate vampires male lover youth henry lowest loyal vampire silent rose martial romance\n",
      "Topic 33: self manner trick bomb limits view demand shallow talent impress mental meaning channel vital favor\n",
      "Topic 34: devil silent damn bless death hip die cruel fear hop hell sky metallica kill god\n",
      "Topic 35: orchestra trash latin waste spending america london stopped broke yard royal garbage overview shelf award\n",
      "Topic 36: es la de este un y el en que una se youth los pound echo\n",
      "Topic 37: usb tech windows software port microsoft ram vista customer driver repair access support samsung drivers\n",
      "Topic 38: movie acting actors cartoon movies actress hollywood scenes comedy director films cinematography comic flick film\n",
      "Topic 39: socket broad bound lights sea tragedy united collection poems trains transmitter string santa personality poetry\n",
      "Topic 40: merit lacking identify rating twist characters complex speed basic profound interpretation details stiff bite follow\n",
      "Topic 41: japan london award government oscar bang hall actress prize england global agent british dawn royal\n",
      "Topic 42: inferior grammar students question error math words vocabulary incorrect language mission test studying confusing organized\n",
      "Topic 43: ear headphones headset motorola chamber phones earbuds static signal antenna ipod reception mic plugs cell\n",
      "Topic 44: recommend accept claim violent prevent editor skip birthday shall recommend york propaganda sudden rush latest\n",
      "Topic 45: menu disk switch discs crash episodes scratch insert port disc plug connector usb mode notebook\n",
      "Topic 46: album song lyrics sing songs tune rock band albums singer cd catchy music tunes tracks\n",
      "Topic 47: friend pump bite internet search benefit want trust prior intend favorite funniest searching finest best\n",
      "Topic 48: kong c bc king mr writer frame stale stage interior russell red design classic scientific\n",
      "Topic 49: smell mask shampoo scent bath sweet hair weather cleans treatment fat skin wash lotion foster\n",
      "Topic 0: 墨 平装 墨水 团 银 纸 纸质 金色 黄 纸张 薄 灰色 厚 分量 版面\n",
      "Topic 1: 退换 部门 员 师傅 电话 人员 投诉 垃圾 当面 恶劣 教训 快递 维修 裂 碎\n",
      "Topic 2: 小时 夜 催 总结 慢 休息 当天 来自 前天 发出 神 晚上 晚 闲 凌晨\n",
      "Topic 3: 儿子 大人 童话 小朋友 小孩子 孩子 故事 绘 图画 岁 小孩 漫画 儿童 猫 屋\n",
      "Topic 4: 速度 书签 下午 很快 库 礼物 好友 德鲁克 滴 天赋 电子版 早晨 生日 震撼 吃惊\n",
      "Topic 5: 捐 环节 号 拜托 免 周边 顾客 处理 取消 链接 用户 预计 枕头 服 亚马逊\n",
      "Topic 6: 娃娃 玩具 姑娘 王子 女儿 可爱 儿子 准 青年 小 嫁 孙 女 夫妇 潘\n",
      "Topic 7: 波特 魔法 哈利 骏 魔 伏地 魔幻 魔杖 春天 巫师 续集 女王 凤凰 哈利波 市场价\n",
      "Topic 8: 中医 人体 家长 病人 治疗 父母 沟通 医生 白领 健康 身体 孩子 养生 生病 疾病\n",
      "Topic 9: 期权 不确定性 资助 资本 资产 风险 规模 投资 模型 收益 货币 交易 条件 动机 定义\n",
      "Topic 10: 非洲 饮食 食物 食品 添加剂 鲜活 美食 食 饭 毒 病 环球 患者 煮 吃\n",
      "Topic 11: 人文 中华民族 人类 文明 民族 哲学 宗教 信仰 神话 史诗 欧洲 上帝 艺术 大自然 文化\n",
      "Topic 12: 数学 教程 基础 摄像头 课堂 课程 入门 初步 易学 典 教学 考研 经济学 讲解 初学者\n",
      "Topic 13: 瑜伽 星星 瘦 减肥 酸 保 冬 妳 肌肤 湿 霜 按摩 男士 痘痘 怀孕\n",
      "Topic 14: 口味 厨房 熟 茶 菜 食谱 美食 面包 旅游 冰 游记 鲜活 水果 地图 食品\n",
      "Topic 15: 音像 海报 相对 录制 改 多媒体 区 发行 广大 文艺 应 起码 合适 丁丁 实惠\n",
      "Topic 16: 一对 攒 马 西 附送 年轻人 愉悦 西方 欢乐 消费者 庆幸 存储 玩家 礼 汶川\n",
      "Topic 17: 轻柔 爆发 柔情 释怀 歌声 些许 全新 夕阳 高音 勾 光辉 难得一见 纯净 翅膀 宽广\n",
      "Topic 18: 组织 员工 职业化 管理 体系 核心 大学生 案例 战略 营销 企业 创业 经理人 创新 成果\n",
      "Topic 19: 人生 乐观 生活 平和 奋斗 成功 心灵 面对 遭遇 梦想 目标 理想 财富 老板 智慧\n",
      "Topic 20: 策划 鬼 猫 关系 阴谋 机关 构思 犯罪 颠覆 重复 吸血鬼 主角 男子 角色 事件\n",
      "Topic 21: 程 清单 目 出品 朵 序 东东 件 来自 得以 排列 条 产 推广 收拾\n",
      "Topic 22: 奥运会 局 牌 球 博弈论 奥运 玩家 游戏 见证 天生 太阳 美 博弈 歌者 主\n",
      "Topic 23: 篇 回 片 损 分 大学 好看 说明书 畅销书 用品 通 托 古文 诗 载\n",
      "Topic 24: 迷 欲 罢 续集 遍 简体 结束 拜读 热情 棒 第二 终 翻阅 读书 书局\n",
      "Topic 25: 明朝 川家康 明月 德川 战国 货币 德 争论 战争 丰臣秀吉 封建 幼稚 抄袭 史实 垃圾\n",
      "Topic 26: 冲破 释放 提琴 弱 挣脱 衬托 束缚 空灵 舒缓 主 架子 完美 挣扎 追求 氛围\n",
      "Topic 27: 盖 锅 玻璃 眼 莲花 滴 盖子 杯子 河童 成立 滑 进口 锁 雨 煲\n",
      "Topic 28: 外国 外国人 美国 基金 英 欧美 名家 译者 原版 国人 英文 国外 北美 译本 翻译\n",
      "Topic 29: 蒋 楼 记录 棉 线索 大厦 建筑 层 台 拖 大陆 孔 书目 查阅 苏醒\n",
      "Topic 30: 宝 帅 有限公司 随杰 迅速 空 派克 速 国际 快捷 贼 海洋 环保 钢笔 数量\n",
      "Topic 31: 丹 墨 证 汪 黄帝内经 墨水 十二 言 注 庄子 宫 胜 可谓 云 论语\n",
      "Topic 32: 情人 女子 杜 悲剧 男人 爱情 纠缠 女主 舒 女人 言情小说 主人公 约翰 女 分手\n",
      "Topic 33: 渠道 影响力 主张 赞同 一致 红 十足 内涵 动物 枪 具 提问 棒 意见 面子\n",
      "Topic 34: 天狼星 杀死 死亡 斯内普 狗 黑夜 大海 利多 生命 内维尔 徒 毁灭 牺牲 忠诚 残忍\n",
      "Topic 35: 交响乐团 北美 指挥 地址 逝世 军刀 柏林 柔和 工艺 周年 欧美 保存 母 剃须刀 全集\n",
      "Topic 36: 伊 途中 确 郭 号称 校园 青 恩 少年 灌水 非 辣 阴影 实验 大方\n",
      "Topic 37: 智能 杀毒 软件 通话 用户 操作系统 互联网 瑞星 手机 本本 微软 驱动 出口 摄像头 内存\n",
      "Topic 38: 台词 动漫 动画片 影片 动画 观看 影 片头 张扬 片子 影院 演员 剧情 本片 导演\n",
      "Topic 39: 眼眶 嫁 围 天边 航线 信件 牵 誓言 宽 思念 胸前 挚爱 针 明天 厚实\n",
      "Topic 40: 未知 彻底 含 生硬 烂烂 之下 对不起 以下 紧凑 本质 有待 后续 因素 颠覆 阴影\n",
      "Topic 41: 皇家 大奖 票房 艺人 约翰 奥斯卡 纪录 丰臣秀吉 英国 鞋 媒体 秀 赢得 捐 节目\n",
      "Topic 42: 解答 对照 题 作文 模拟 解析 词典 试题 文本 校对 错字 习题 考试 字母 有待\n",
      "Topic 43: 耳机 信号 噪音 数据线 耳 原配 耳塞 音量 低音 原装 耳朵 充电器 森海塞尔 播放器 音质\n",
      "Topic 44: 趋势 好好 要求 建议 考验 应 狂 最新 前进 巴菲特 出版 安 就要 引用 避免\n",
      "Topic 45: 舞毯 跳 切换 花絮 转换 本本 硬件 字幕 点击 插头 正常 运输 安装 菜单 插入\n",
      "Topic 46: 专辑 画册 唱歌 歌词 情歌 歌 曲目 歌曲 支 曲子 首 音乐 宋 曲 节奏\n",
      "Topic 47: 好友 购书 网友 信赖 收藏 网购 值得 购买 推荐 畅销 搜索 排行榜 最好 省 鲁迅\n",
      "Topic 48: 论语 夏 丹 孔子 陈 格 多久 电视台 紫 明 庄子 杨 帅 薛 台\n",
      "Topic 49: 香味 味道 洗发水 喷 闻 乳液 好闻 淘 气息 味 洗面奶 气味 面膜 皮肤 干净\n",
      "TD: 0.75467\n",
      "{'intra_en': {'acc': 0.7924, 'macro-F1': 0.7922507862046837}, 'intra_cn': {'acc': 0.723, 'macro-F1': 0.7159996760140708}, 'cross_en': {'acc': 0.658, 'macro-F1': 0.6344931741279648}, 'cross_cn': {'acc': 0.653, 'macro-F1': 0.6487342142471864}}\n"
     ]
    }
   ],
   "source": [
    "########################### Evaluate ####################################\n",
    "from topmost import eva\n",
    "\n",
    "# get theta (doc-topic distributions)\n",
    "train_theta_en, train_theta_cn, test_theta_en, test_theta_cn = trainer.export_theta()\n",
    "\n",
    "# compute topic coherence (CNPMI)\n",
    "# refer to https://github.com/BobXWu/CNPMI\n",
    "\n",
    "# compute topic diversity\n",
    "TD = eva.multiaspect_diversity((top_words_en, top_words_cn))\n",
    "print(f\"TD: {TD:.5f}\")\n",
    "\n",
    "# evaluate classification\n",
    "results = eva.crosslingual_cls(\n",
    "    train_theta_en,\n",
    "    train_theta_cn,\n",
    "    test_theta_en,\n",
    "    test_theta_cn,\n",
    "    dataset.train_labels_en,\n",
    "    dataset.train_labels_cn,\n",
    "    dataset.test_labels_en,\n",
    "    dataset.test_labels_cn,\n",
    "    classifier=\"SVM\",\n",
    "    gamma=\"auto\"\n",
    ")\n",
    "\n",
    "print(results)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "torch1.13py3.8",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.17"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
